package com.fesine.quartz.chapter7;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.jobs.FileScanJob;

import java.util.Date;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2016/11/19 22:28
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/11/19 22:28
 */
public class Listing_7_13 {
    static Log logger = LogFactory.getLog(Listing_7_13.class);

    public static void main(String[] args) {

        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            //将文件监听器添加到scheduler上下文中
            scheduler.getContext().put(SimpleFileScanListener.class.getSimpleName(), new
                    SimpleFileScanListener());
            //创建文件扫描任务实例
            JobDetail jobDetail = new JobDetail(FileScanJob.class.getSimpleName(), FileScanJob
                    .class);
            JobDataMap dataMap = new JobDataMap();
            //添加监听路径和所使用的监听器名称
            dataMap.put(FileScanJob.FILE_NAME, "d:/jsonFile/1.txt");
            dataMap.put(FileScanJob.FILE_SCAN_LISTENER_NAME, SimpleFileScanListener.class
                    .getSimpleName());
            //将监听参数添加到jobDetail中
            jobDetail.setJobDataMap(dataMap);
            Trigger trigger = TriggerUtils.makeSecondlyTrigger(30);
            trigger.setName("fileScanTrigger");
            trigger.setStartTime(new Date());
            scheduler.scheduleJob(jobDetail, trigger);
            scheduler.start();
            logger.info("scheduler starting up...");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }

    }

}
